package com.ftg.learn.chapter17.generic;

import java.util.Vector;

/**
 * @author KangJx
 * @date 2021/8/5
 */
public class MyStackImple<T> implements IstackGeneric<T> {

    /**
     * 默认存放的元素的动态数组，
     *    不用再自己进行扩展了
     */
    private Vector<T> obj;

    public MyStackImple(){
        //所有的扩展全部采用Vector默认方式
        obj = new Vector<>();
    }

    @Override
    public T push(T t1) {
        obj.add(t1);
        return t1;
    }

    @Override
    public T pop() {
        T t1 = obj.get(obj.size() - 1);
        obj.remove(obj.size() - 1);
        return t1;
    }

    @Override
    public T peek() {
        return obj.get(obj.size() - 1);
    }
}
